/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import dao.CategoryJpaController;
import dao.ProductJpaController;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Persistence;
import pojo.Category;
import pojo.Product;

/**
 *
 * @author khalifaabdelaziz
 */
public class ServiceSearch {
    public List<Product> searchByCategoryName(String name,String Gender,int Kids){
          CategoryJpaController categoryController = new CategoryJpaController(Persistence.createEntityManagerFactory("ServletProjectPU"));
        List<Category> categorys =categoryController.findCategoryByAll(name, Gender, Kids);
       List<Product> products = new ArrayList<Product>();
        ProductJpaController productController =new ProductJpaController(Persistence.createEntityManagerFactory("ServletProjectPU"));
        for (Category category : categorys) {
           
            products.addAll(productController.findProductByCategory(category.getId()));
        }
        
        return products;
        
    }
    public List<Product> searchByPrice(int price1,int price2){
       ProductJpaController productController =new ProductJpaController(Persistence.createEntityManagerFactory("ServletProjectPU"));
        
        return productController.findProductByprice(price1,price2);
    }
}
